// pages/test/test.js
var app = getApp()

Page({

  /**
   * 页面的初始数据
   */
  data: {

  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.getInitSDKInfo()
    this.getInitSDKInfo1()
  },  

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },
  loginTangqiaoWithParam: function () {
    // wx.navigateTo({
    //   url: '/pages/tangqiao/index?roomName=999999&displayName=seeking',
    // })
    this.queryMeeting2()
  },

  loginTangqiao() {
    wx.navigateTo({
      url: '/pages/tangqiao/index'
    })
  },
  loginTengxunWithParam: function () {
    this.queryMeeting()

  },

  loginTengxun() {
    
  },

  // 创建唐桥会议
  createMeeting() {
    wx.request({
      url: 'https://atagmp.bsoft.com.cn/videoTest/api/SCCTest/createMeeting',
      method: 'POST',
      data: { "businessId": "130" },
      success: function (res) {
        if (!res.data.data) {
          wx.showToast({
            title: res.data.message,
          })
          return
        }
        let data = res.data.data
        let randomId = Math.ceil(Math.random() * 1e6)

        app.globalData.tangqiaoConfig.roomId = data.meetingId
        app.globalData.tangqiaoConfig.token = data.token
        app.globalData.tangqiaoConfig.userId = randomId
        let url = `/pages/tangqiao/index?roomName=${data.meetingId}&displayName=${randomId}`;
        wx.navigateTo({
          url: url,
        })
      }
    })
  },

  // 查询唐桥会议
  queryMeeting2() {
    wx.request({
      url: 'https://atagmp.bsoft.com.cn/videoTest/api/SCCTest/queryMeeting',
      method: 'POST',
      data: { "businessId": "130" },
      success: function (res) {
        if (!res.data.data){
          wx.showToast({
            title: res.data.message,
          })
          return
        }
        let data = res.data.data
        let randomId = Math.ceil(Math.random() * 1e6)

        app.globalData.tangqiaoConfig.roomId = data.meetingId
        app.globalData.tangqiaoConfig.token = data.token
        app.globalData.tangqiaoConfig.userId = randomId
        let url = `/pages/tangqiao/index?roomName=${data.meetingId}&displayName=${randomId}`;
        wx.navigateTo({
          url: url,
        })
      }
    })
  },
  // 初始化唐桥sdk
  getInitSDKInfo1() {
    wx.request({
      url: 'https://atagmp.bsoft.com.cn/videoTest/api/SCCTest/getInitSDKInfo',
      method: 'POST',
      data: {},
      success: function (res) {
        let data = res.data.data
        app.globalData.rtcConfig.appKey = data.appKey
      }
    })
  },



  // 查询腾讯会议
  queryMeeting() {
    wx.request({
      url: 'https://atagmp.bsoft.com.cn/videoTest/api/TRTCTest/queryMeeting',
      method: 'POST',
      data: { "businessId": "8888" },
      success: function (res) {
        if (!res.data.data) {
          wx.showToast({
            title: res.data.message,
          })
          return
        }
        let data = res.data.data
        app.globalData.rtcConfig.roomId = data.meetingId
        app.globalData.rtcConfig.userSig = data.joinToken
        app.globalData.rtcConfig.userId = data.joinUserId
        let url = `/pages/meeting/meeting?roomName=${data.meetingId}&displayName=${data.joinUserId}`;
        wx.navigateTo({
          url: url,
        })
      }
    })
  },

  // 初始化腾讯会议
  getInitSDKInfo (){
    wx.request({
      url: 'https://atagmp.bsoft.com.cn/videoTest/api/TRTCTest/getInitSDKInfo',
      method: 'POST',
      data: { },
      success: function (res) {
        let data = res.data.data
        app.globalData.rtcConfig.sdkAppId = data.appKey
      }
    })
  }
})